package com.ebelter.bodyfatscale.util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;

import com.ebelter.bodyfatscale.R;

/**
 * Created by ZCQ on 2017/11/27
 */

public class ToastUtil {

    private static Toast mToast;

    public static void show(String str,int gravity) {
      show(str,Toast.LENGTH_SHORT,gravity);
    }
    public static void show(String str, int duration,int gravity) {
        mToast.setGravity(gravity,0,0);

        mToast.setDuration(duration);
        TextView textView= (TextView) mToast.getView();
        textView.setText(str);
       // mToast.setText(str);
        mToast.show();
    }

    public static void show(String str) {
        show(str, Toast.LENGTH_SHORT,Gravity.CENTER);
    }

    public static void show(int res,int gravity) {
        show(res, Toast.LENGTH_SHORT,gravity);
    }

    public static void show(int strRes, int duration,int grivty) {
        mToast.setGravity(grivty,0,0);
        mToast.setDuration(duration);
        TextView textView= (TextView) mToast.getView();
        textView.setText(strRes);
       // mToast.setText(strRes);
        mToast.show();
    }

    public static void show(int strRes) {
        show(strRes, Toast.LENGTH_SHORT,Gravity.CENTER);
    }

    @SuppressLint("ShowToast")
    public static void init(Context context) {
      //  mToast = Toast.makeText(ApplicationHelper.mApplicationContecx, "", Toast.LENGTH_SHORT);
        mToast=new Toast(context);
        mToast.setDuration(Toast.LENGTH_SHORT);
        TextView view = new TextView(context);
        view.setBackgroundResource(R.drawable.sp_s879598_r6);
        view.setTextColor(Color.WHITE);
        view.setPadding(20, 10, 20, 10);
        view.setGravity(Gravity.CENTER);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setView(view);

    }

    public static void showGravity(int strRes,int gravity){
        show(strRes,gravity);
    }
}
